<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>语句</title>
</head>

<body>
  <script>
    //if
    let j;
    if (j > 25) {
      console.log("Greater than 25.")
    } else {
      console.log("Less than 25.")
    }
    //do-while
    let i = 0;
    do {
      i += 2;
      console.log(i);
    } while (i < 10);
    //while
    let k = 0;
    while (k < 10) {
      console.log(k)
      k += 2;
    }
    //for
    let count = 10;
    for (let i = 0; i < count; i++) {
      console.log(i);
    }
    //for-in
    for (const propName in window) {
      document.write(propName + "<br/>");
    }
    //for-of语句
    for (const el of [2, 4, 6, 8]) {
      document.write(el); //2468
    }
    //标签语句
    start: for (let i = 0; i < count; i++) {
      console.log(i);
    }
    //break和continue
    let num = 0;
    for (let i = 1; i < 10; i++) {
      if (i % 5 === 0) {
        break;
        // continue; 换成continue会跳出本次循环,输出8.
      }
      num++;
    }
    console.log(num);//4
    //嵌套for与标签语句.
    let num1 = 0;
    outer:
    for (let i = 0; i < 10; i++) {
      for (let j = 0; j < 10; j++) {
        if (i === 5 && j === 5) {
          break outer;
          // continue outer;  会输出95.
        }
        num1++;
      }
    }
    console.log(num1);//55
    //switch
    let num2 = 25;
    switch(true){
      case num2 < 0:
        console.log("Less than 0");
        break;
      case num2 >=0 && num2 <=10:
        console.log("Between 0 and 10");
        break;
      case num2 > 10 && num2 <=20:
        console.log("Between 10 and 20");
        break;
      default:
        console.log("More than 20.")
    }
    //不指定返回值,默认返回undefined.
    function sayHi(name,message){
      console.log("Hello "+name + ", " + message);
    }
    sayHi("Sloan","How are you?");
  </script>
</body>

</html>